package com.itheima.controller;

import com.itheima.domain.Users;
import com.itheima.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/user")
public class LoginController {
    @Autowired
    private LoginService loginService;
    @RequestMapping("/doLogin")
    public ModelAndView doLogin(String username){
        Users user = loginService.login(username);
        ModelAndView mv = new ModelAndView();
        mv.addObject("user",user);
        mv.setViewName("success");
        return mv;

    }
    @RequestMapping("/doRegister")
    public String doRegister(Users users){
        loginService.save(users);
        return "redirect:/user/doLogin";
    }

}
